package Swing;

import Databases.*;
import MsgSystem.*;
import UserUnit.ImpPhoto;
import UserUnit.ImpSamplePhoto;
import java.awt.GridBagConstraints;
import javax.swing.*;
import java.awt.*;
import java.awt.List;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.awt.image.renderable.ParameterBlock;
import java.awt.print.PrinterException;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import javax.swing.ImageIcon;
import java.awt.image.BufferedImage;
import javax.swing.tree.*;
import javax.swing.tree.TreePath;
import com.sun.media.jai.widget.DisplayJAI;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.RescaleOp;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.InterpolationNearest;
import javax.imageio.ImageIO;
import javax.media.jai.InterpolationBilinear;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.media.jai.*;

public class Tabs extends javax.swing.JFrame {

    ImpInstantMessage itm;
    int cont = 0;
    ImpListener listener;
    Inicio inicio = new Inicio();
    ArrayList contacts = null;
    ArrayList<ImpPhoto> results;
    ArrayList<ArrayList> totalResults;
    File fileObtained;
    ArrayList tagsList = new ArrayList();
    String comment;
    ImageIcon icon;
    DefaultMutableTreeNode rama, seleccion, node;
    DefaultTreeModel treeModel;
    Map<String, String> taxs = new HashMap<String, String>();
    String taxType, selected, libraryClick;
    String taxType_name = "";
    ImpPhoto tempo;
    String userCatch;
    boolean path = false;
    private PlanarImage imagePlanar;
    File phototoEdit;
    private JSlider slider;
    ArrayList<Integer> numbers;
    float numero;
    GridBagConstraints constraints;
    PlanarImage scaledImage;
    PlanarImage scaledImageprin;
    PlanarImage scaledImageRotate;
    private DisplayJAI display;
    private DisplayJAI displayUpload;

    public Tabs(ImpInstantMessage itm) {
        this.itm = itm;
        listener = new ImpListener(itm);

        initComponents();

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane5 = new javax.swing.JTabbedPane();
        jMenu1 = new javax.swing.JMenu();
        buttonGroup1 = new javax.swing.ButtonGroup();
        menu = new javax.swing.JTabbedPane();
        Library = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        jLayeredPane7 = new javax.swing.JLayeredPane();
        jSeparator7 = new javax.swing.JSeparator();
        LocalSearchTitle = new javax.swing.JLabel();
        LocalSearchField = new javax.swing.JTextField();
        SearchButton = new javax.swing.JButton();
        TreeMenuText = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        LibraryTree = new javax.swing.JTree();
        jButton10 = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        PreviewTitle = new javax.swing.JLabel();
        LibraryDeletePhotoButton = new javax.swing.JButton();
        LibraryPresentationButton = new javax.swing.JButton();
        jPanel15 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        Editor = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLayeredPane3 = new javax.swing.JLayeredPane();
        SelectImageEditorButton = new javax.swing.JButton();
        LuminanceText = new javax.swing.JLabel();
        LuminanceSlider = new javax.swing.JSlider();
        SharpeningSlider = new javax.swing.JSlider();
        SharpeningText = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        EdgeDetectionButton = new javax.swing.JButton();
        EditorSaveButton = new javax.swing.JButton();
        EditorDiscardButton = new javax.swing.JButton();
        EditorShareButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jPanel5 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        zoomin = new javax.swing.JButton();
        zoomout = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        panelEditScroll = new javax.swing.JPanel();
        editScroll = new javax.swing.JScrollPane();
        picCont = new javax.swing.JLabel();
        Search = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jLayeredPane9 = new javax.swing.JLayeredPane();
        SearchText = new javax.swing.JLabel();
        SearchField = new javax.swing.JTextField();
        SearcherSearchButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        OntologiesSearcher = new javax.swing.JTree();
        DifferentNewsSearchMenu = new javax.swing.JComboBox();
        CheckBoxCategories = new javax.swing.JCheckBox();
        CheckBoxNews = new javax.swing.JCheckBox();
        AllCategoriesSelectedField = new javax.swing.JTextField();
        jSeparator5 = new javax.swing.JSeparator();
        jPanel13 = new javax.swing.JPanel();
        ResultsText = new javax.swing.JLabel();
        SearcherClearButton = new javax.swing.JButton();
        jPanel14 = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        showLabelResults = new javax.swing.JLabel();
        downloadPhoto = new javax.swing.JButton();
        Upload = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLayeredPane4 = new javax.swing.JLayeredPane();
        SelectFileButton = new javax.swing.JButton();
        UploadButton = new javax.swing.JButton();
        EditPhotoButton = new javax.swing.JButton();
        SelectFileField = new javax.swing.JTextField();
        SelectFileText = new javax.swing.JLabel();
        TagsField = new javax.swing.JTextField();
        AddTagsField = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        OntologiesUpload = new javax.swing.JTree();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        AddCommentText = new javax.swing.JLabel();
        CommentsField = new javax.swing.JTextField();
        jSeparator6 = new javax.swing.JSeparator();
        jButton9 = new javax.swing.JButton();
        CheckBoxCategoUpload = new javax.swing.JCheckBox();
        jPanel12 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        panelDePhoto = new javax.swing.JPanel();
        showPreview = new javax.swing.JLabel();
        LogoutButton = new javax.swing.JButton();

        jMenu1.setText("jMenu1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PhotoWorld");

        menu.setBackground(new java.awt.Color(204, 204, 204));
        menu.setMinimumSize(new java.awt.Dimension(800, 600));

        Library.setMinimumSize(new java.awt.Dimension(100, 300));

        jLayeredPane7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jSeparator7.setBounds(10, 130, 200, 10);
        jLayeredPane7.add(jSeparator7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        LocalSearchTitle.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        LocalSearchTitle.setText("Local Search:");
        LocalSearchTitle.setBounds(10, 10, 100, 17);
        jLayeredPane7.add(LocalSearchTitle, javax.swing.JLayeredPane.DEFAULT_LAYER);
        LocalSearchField.setBounds(10, 40, 180, 30);
        jLayeredPane7.add(LocalSearchField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SearchButton.setText("Search");
        SearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                localSearchButton(evt);
            }
        });
        SearchButton.setBounds(10, 90, 90, 23);
        jLayeredPane7.add(SearchButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TreeMenuText.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        TreeMenuText.setText("Tree menu:");
        TreeMenuText.setBounds(10, 140, 90, 17);
        jLayeredPane7.add(TreeMenuText, javax.swing.JLayeredPane.DEFAULT_LAYER);

        node = new DefaultMutableTreeNode("Outcoming");
        DefaultMutableTreeNode temp;
        File file=new File ("outcoming");
        treeModel = new DefaultTreeModel(node);
        File[] filesTree = file.listFiles(new ImageFileFilter());
        for (File f : filesTree)
        {
            temp=new DefaultMutableTreeNode(f.getName());
            treeModel.insertNodeInto(temp, node, 0);

        }
        LibraryTree= new javax.swing.JTree(treeModel);
        LibraryTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                libraryTreeClick(evt);
            }
        });
        jScrollPane2.setViewportView(LibraryTree);

        jScrollPane2.setBounds(20, 170, 190, 240);
        jLayeredPane7.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton10.setText("Clear");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearLocal(evt);
            }
        });
        jButton10.setBounds(120, 90, 90, 23);
        jLayeredPane7.add(jButton10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane7, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        PreviewTitle.setFont(new java.awt.Font("Tahoma", 3, 36)); // NOI18N
        PreviewTitle.setText("My Photos:");

        LibraryDeletePhotoButton.setText("Delete");

        LibraryPresentationButton.setText("Presentation");

        jPanel15.setBackground(new java.awt.Color(0, 51, 51));
        jPanel15.setPreferredSize(new java.awt.Dimension(748, 383));

        jLabel1.setBackground(new java.awt.Color(0, 51, 51));
        jLabel1.setFont(new java.awt.Font("Impact", 0, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        File filefil = new File("icons","image_48.png");

        PlanarImage im = JAI.create("fileload",filefil.getPath());
        BufferedImage image = resize(im,300,300);
        jLabel1.setIcon(new ImageIcon(image));
        jLabel1.setText("Select any photo");

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addGap(123, 123, 123)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 616, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(132, Short.MAX_VALUE))
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, 871, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(PreviewTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 551, Short.MAX_VALUE)
                        .addComponent(LibraryDeletePhotoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(LibraryPresentationButton)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PreviewTitle)
                    .addComponent(LibraryDeletePhotoButton)
                    .addComponent(LibraryPresentationButton))
                .addGap(18, 18, 18)
                .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(49, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout LibraryLayout = new javax.swing.GroupLayout(Library);
        Library.setLayout(LibraryLayout);
        LibraryLayout.setHorizontalGroup(
            LibraryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LibraryLayout.createSequentialGroup()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        LibraryLayout.setVerticalGroup(
            LibraryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        menu.addTab("LIBRARY", Library);

        Editor.setMinimumSize(new java.awt.Dimension(100, 300));

        jLayeredPane3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLayeredPane3.setEnabled(false);

        SelectImageEditorButton.setText("Select image");
        SelectImageEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectImageEditorButtonActionPerformed(evt);
            }
        });
        SelectImageEditorButton.setBounds(50, 10, 110, 30);
        jLayeredPane3.add(SelectImageEditorButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        LuminanceText.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        LuminanceText.setText("Smooth:");
        LuminanceText.setBounds(20, 110, 80, 17);
        jLayeredPane3.add(LuminanceText, javax.swing.JLayeredPane.DEFAULT_LAYER);

        LuminanceSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                LuminanceSliderStateChanged(evt);
            }
        });
        LuminanceSlider.setBounds(10, 140, 200, 25);
        jLayeredPane3.add(LuminanceSlider, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SharpeningSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                SharpeningSliderStateChanged(evt);
            }
        });
        SharpeningSlider.setBounds(10, 220, 200, 25);
        jLayeredPane3.add(SharpeningSlider, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SharpeningText.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        SharpeningText.setText("Brightness:");
        SharpeningText.setBounds(20, 200, 90, 15);
        jLayeredPane3.add(SharpeningText, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator1.setBounds(10, 350, 200, 10);
        jLayeredPane3.add(jSeparator1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EdgeDetectionButton.setText("Edge Detection");
        EdgeDetectionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EdgeDetectionButtonActionPerformed(evt);
            }
        });
        EdgeDetectionButton.setBounds(40, 300, 140, 23);
        jLayeredPane3.add(EdgeDetectionButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EditorSaveButton.setText("Save");
        EditorSaveButton.setBounds(20, 380, 80, 23);
        jLayeredPane3.add(EditorSaveButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EditorDiscardButton.setText("Discard");
        EditorDiscardButton.setBounds(130, 380, 80, 23);
        jLayeredPane3.add(EditorDiscardButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EditorShareButton.setText("Share");
        EditorShareButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditorShareButtonActionPerformed(evt);
            }
        });
        EditorShareButton.setBounds(70, 430, 90, 23);
        jLayeredPane3.add(EditorShareButton, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator2.setBounds(10, 50, 200, 10);
        jLayeredPane3.add(jSeparator2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane3, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Preview:");

        zoomin.setText("Zoom In");
        zoomin.setFocusable(false);
        zoomin.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomin.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        zoomin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editZoomIn(evt);
            }
        });

        zoomout.setText("Zoom Out");
        zoomout.setFocusable(false);
        zoomout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        zoomout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editZoomOut(evt);
            }
        });

        jButton1.setText("Rotate Right");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editRotateRight(evt);
            }
        });

        jButton4.setText("Rotate Left");
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editRotateLeft(evt);
            }
        });

        panelEditScroll.setEnabled(false);
        panelEditScroll.setPreferredSize(new java.awt.Dimension(861, 362));

        editScroll.setEnabled(false);
        editScroll.setFocusable(true);
        editScroll.setPreferredSize(new java.awt.Dimension(0, 0));

        picCont.setAlignmentX(0.5F);
        picCont.setEnabled(false);

        javax.swing.GroupLayout panelEditScrollLayout = new javax.swing.GroupLayout(panelEditScroll);
        panelEditScroll.setLayout(panelEditScrollLayout);
        panelEditScrollLayout.setHorizontalGroup(
            panelEditScrollLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(editScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 861, Short.MAX_VALUE)
            .addGroup(panelEditScrollLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelEditScrollLayout.createSequentialGroup()
                    .addGap(297, 297, 297)
                    .addComponent(picCont, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(302, Short.MAX_VALUE)))
        );
        panelEditScrollLayout.setVerticalGroup(
            panelEditScrollLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(editScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
            .addGroup(panelEditScrollLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(picCont, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(213, 213, 213)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zoomin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zoomout)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(panelEditScroll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(108, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(30, 30, 30)
                .addComponent(panelEditScroll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(zoomin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(zoomout, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(44, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout EditorLayout = new javax.swing.GroupLayout(Editor);
        Editor.setLayout(EditorLayout);
        EditorLayout.setHorizontalGroup(
            EditorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(EditorLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        EditorLayout.setVerticalGroup(
            EditorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        menu.addTab("EDITOR", Editor);

        Search.setMinimumSize(new java.awt.Dimension(100, 300));

        jLayeredPane9.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        SearchText.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        SearchText.setText("Search:");
        SearchText.setBounds(10, 10, 100, 17);
        jLayeredPane9.add(SearchText, javax.swing.JLayeredPane.DEFAULT_LAYER);
        SearchField.setBounds(10, 40, 180, 30);
        jLayeredPane9.add(SearchField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SearcherSearchButton.setText("Search");
        SearcherSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearcherSearchButtonActionPerformed(evt);
            }
        });
        SearcherSearchButton.setBounds(20, 450, 80, 23);
        jLayeredPane9.add(SearcherSearchButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Categories");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Animals");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Insect");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Reptile");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Bird");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Mammal");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("News");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sports");
        javax.swing.tree.DefaultMutableTreeNode treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Football");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Basket");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Tennis");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Technologies and Internet");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Mobiles");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Travel");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Games");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Commputers");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Top Stories");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("National");
        javax.swing.tree.DefaultMutableTreeNode treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Barcelona");
        treeNode4.add(treeNode5);
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Madrid");
        treeNode4.add(treeNode5);
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("International");
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Italy");
        treeNode4.add(treeNode5);
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("France");
        treeNode4.add(treeNode5);
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Colombia");
        treeNode4.add(treeNode5);
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        OntologiesSearcher.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        OntologiesSearcher.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                searchOntologyTree(evt);
            }
        });
        jScrollPane3.setViewportView(OntologiesSearcher);

        jScrollPane3.setBounds(20, 160, 190, 140);
        jLayeredPane9.add(jScrollPane3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        DifferentNewsSearchMenu.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "On News Titles", "On Paragraphs", "On Adjacent Paragraphs", "On Photos Keywords" }));
        DifferentNewsSearchMenu.setBounds(20, 380, 150, 30);
        jLayeredPane9.add(DifferentNewsSearchMenu, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CheckBoxCategories.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        CheckBoxCategories.setText("By Categories:");
        CheckBoxCategories.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CheckBoxCategoriesActionPerformed(evt);
            }
        });
        CheckBoxCategories.setBounds(10, 120, 130, 25);
        jLayeredPane9.add(CheckBoxCategories, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CheckBoxNews.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        CheckBoxNews.setText("By News:");
        CheckBoxNews.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CheckBoxNewsActionPerformed(evt);
            }
        });
        CheckBoxNews.setBounds(10, 350, 100, 25);
        jLayeredPane9.add(CheckBoxNews, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AllCategoriesSelectedField.setText("All Categories selected");
        AllCategoriesSelectedField.setBounds(20, 310, 190, 30);
        jLayeredPane9.add(AllCategoriesSelectedField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator5.setBounds(10, 110, 210, 10);
        jLayeredPane9.add(jSeparator5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane9, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        jPanel13.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        ResultsText.setFont(new java.awt.Font("Tahoma", 3, 36)); // NOI18N
        ResultsText.setText("Results:");

        SearcherClearButton.setText("Clear");
        SearcherClearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clear(evt);
            }
        });

        jPanel14.setBackground(new java.awt.Color(255, 255, 255));
        jPanel14.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jSplitPane2.setDividerLocation(250);

        DefaultMutableTreeNode node;
        DefaultTreeModel treeModel;
        node = new DefaultMutableTreeNode("Photos");
        treeModel = new DefaultTreeModel(node);
        jTree1 = new javax.swing.JTree(treeModel);
        jScrollPane5.setViewportView(jTree1);

        jSplitPane2.setLeftComponent(jScrollPane5);

        showLabelResults.setBackground(new java.awt.Color(0, 51, 51));
        jSplitPane2.setRightComponent(showLabelResults);

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane2)
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)
        );

        downloadPhoto.setText("Download photo");
        downloadPhoto.setVisible(false);
        downloadPhoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadPhotoAction(evt);
            }
        });

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel13Layout.createSequentialGroup()
                        .addComponent(ResultsText, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 658, Short.MAX_VALUE)
                        .addComponent(downloadPhoto, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(SearcherClearButton))
                    .addComponent(jPanel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ResultsText)
                    .addComponent(SearcherClearButton)
                    .addComponent(downloadPhoto))
                .addGap(18, 18, 18)
                .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(56, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout SearchLayout = new javax.swing.GroupLayout(Search);
        Search.setLayout(SearchLayout);
        SearchLayout.setHorizontalGroup(
            SearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(SearchLayout.createSequentialGroup()
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        SearchLayout.setVerticalGroup(
            SearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        menu.addTab("SEARCHER", Search);

        Upload.setMinimumSize(new java.awt.Dimension(100, 300));

        jLayeredPane4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        SelectFileButton.setText("...");
        SelectFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SelectFileButtonActionPerformed(evt);
            }
        });
        SelectFileButton.setBounds(180, 40, 30, 30);
        jLayeredPane4.add(SelectFileButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        UploadButton.setText("Upload");
        UploadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                upload(evt);
            }
        });
        UploadButton.setBounds(10, 460, 90, 30);
        jLayeredPane4.add(UploadButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        EditPhotoButton.setText("Edit Photo");
        EditPhotoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditPhotoButtonActionPerformed(evt);
            }
        });
        EditPhotoButton.setBounds(110, 460, 110, 30);
        jLayeredPane4.add(EditPhotoButton, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SelectFileField.setText(null);
        SelectFileField.setBounds(10, 40, 160, 30);
        jLayeredPane4.add(SelectFileField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        SelectFileText.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        SelectFileText.setText("Select File:");
        SelectFileText.setBounds(10, 10, 80, 17);
        jLayeredPane4.add(SelectFileText, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TagsField.setText("tags...");
        TagsField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                click(evt);
            }
        });
        TagsField.setBounds(10, 120, 130, 30);
        jLayeredPane4.add(TagsField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AddTagsField.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        AddTagsField.setText("Add tags:");
        AddTagsField.setBounds(10, 90, 80, 17);
        jLayeredPane4.add(AddTagsField, javax.swing.JLayeredPane.DEFAULT_LAYER);

        treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Categories");
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Animals");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Insect");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Reptile");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Bird");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Mammal");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("News");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sports");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Football");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Basket");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Tennis");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Technologies and Internet");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Mobiles");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Travel");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Games");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Commputers");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Top Stories");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("National");
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Barcelona");
        treeNode4.add(treeNode5);
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Madrid");
        treeNode4.add(treeNode5);
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("International");
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Italy");
        treeNode4.add(treeNode5);
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("France");
        treeNode4.add(treeNode5);
        treeNode5 = new javax.swing.tree.DefaultMutableTreeNode("Colombia");
        treeNode4.add(treeNode5);
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        OntologiesUpload.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        OntologiesUpload.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UploadOntologyListener(evt);
            }
        });
        jScrollPane4.setViewportView(OntologiesUpload);

        jScrollPane4.setBounds(10, 200, 200, 160);
        jLayeredPane4.add(jScrollPane4, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator3.setBounds(10, 80, 200, 10);
        jLayeredPane4.add(jSeparator3, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator4.setBounds(10, 370, 200, 10);
        jLayeredPane4.add(jSeparator4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        AddCommentText.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        AddCommentText.setText("Add comment:");
        AddCommentText.setBounds(10, 380, 120, 17);
        jLayeredPane4.add(AddCommentText, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CommentsField.setText("comments...");
        CommentsField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                deleteComments(evt);
            }
        });
        CommentsField.setBounds(10, 410, 200, 30);
        jLayeredPane4.add(CommentsField, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jSeparator6.setBounds(10, 160, 200, 10);
        jLayeredPane4.add(jSeparator6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton9.setText("Add tag");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTag(evt);
            }
        });
        jButton9.setBounds(150, 120, 70, 30);
        jLayeredPane4.add(jButton9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        CheckBoxCategoUpload.setText("Categories");
        CheckBoxCategoUpload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CheckBoxCategoUploadActionPerformed(evt);
            }
        });
        CheckBoxCategoUpload.setBounds(10, 170, 100, 23);
        jLayeredPane4.add(CheckBoxCategoUpload, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane4, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        jPanel12.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Preview:");

        jButton7.setText("Rotate Right");
        jButton7.setFocusable(false);
        jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UpdateRotateRight(evt);
            }
        });

        jButton8.setText("Rotate Left");
        jButton8.setFocusable(false);
        jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                UploadRotateLeft(evt);
            }
        });

        panelDePhoto.setBackground(new java.awt.Color(0, 51, 51));

        showPreview.setBackground(new java.awt.Color(0, 51, 51));
        showPreview.setOpaque(true);

        javax.swing.GroupLayout panelDePhotoLayout = new javax.swing.GroupLayout(panelDePhoto);
        panelDePhoto.setLayout(panelDePhotoLayout);
        panelDePhotoLayout.setHorizontalGroup(
            panelDePhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelDePhotoLayout.createSequentialGroup()
                .addContainerGap(57, Short.MAX_VALUE)
                .addComponent(showPreview, javax.swing.GroupLayout.PREFERRED_SIZE, 616, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55))
        );
        panelDePhotoLayout.setVerticalGroup(
            panelDePhotoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(showPreview, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel12Layout.createSequentialGroup()
                        .addGap(159, 159, 159)
                        .addComponent(jButton8)
                        .addGap(144, 144, 144)
                        .addComponent(jButton7))
                    .addComponent(jLabel8)
                    .addComponent(panelDePhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(289, Short.MAX_VALUE))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelDePhoto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(17, 17, 17)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(43, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout UploadLayout = new javax.swing.GroupLayout(Upload);
        Upload.setLayout(UploadLayout);
        UploadLayout.setHorizontalGroup(
            UploadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(UploadLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        UploadLayout.setVerticalGroup(
            UploadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        menu.addTab("UPLOAD", Upload);

        LogoutButton.setText("Logout");
        LogoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Logout(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(menu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(LogoutButton)
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(LogoutButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(menu, javax.swing.GroupLayout.PREFERRED_SIZE, 537, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private static BufferedImage resize(PlanarImage image, float targetWidth, float targetHeight) {
        float scale = 1.0F;

        float s1 = (float) targetWidth / (float) image.getWidth();
        float s2 = (float) targetHeight / (float) image.getHeight();

        if (s1 > s2) {
            //scale = s1;
            scale = s2;
        } else {
            //scale = s2;
            scale = s1;
        }

        InterpolationBilinear interp = new InterpolationBilinear();

        ParameterBlock parameters = new ParameterBlock();

        /*
         * ---- ------ ----- --------
         */
        parameters.addSource(image);
        parameters.add(scale);
        parameters.add(scale);
        parameters.add(0.0F);
        parameters.add(0.0F);
        parameters.add(interp);
        /*
         * --- ------ ----- --------
         */



        PlanarImage temp = JAI.create("scale", parameters);
        return temp.getAsBufferedImage();
    }
    private void FreeSearchGeneralMenuFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FreeSearchGeneralMenuFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FreeSearchGeneralMenuFieldActionPerformed

    private void SearcherSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearcherSearchButtonActionPerformed
        showLabelResults.setText(null);
        showLabelResults.setIcon(null);
        results = new ArrayList();
        ImpSearchProfile isp = null;
        if (CheckBoxCategories.isSelected()) {
            if (OntologiesSearcher.getLastSelectedPathComponent() != null) {
                if (OntologiesSearcher.getLastSelectedPathComponent().toString().equalsIgnoreCase("categories")) {
                    JOptionPane.showMessageDialog(null, "Categories isn't an ontology. Select another item of the tree.",
                            "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    String taxType_name1;
                    taxType_name1 = OntologiesSearcher.getLastSelectedPathComponent().toString().toLowerCase(Locale.FRENCH);
                    isp = new ImpSearchProfile(SearchField.getText(), taxType_name1, "free_search", "SEARCH_PROFILE");
                }
            }
        } else {
            isp = new ImpSearchProfile(SearchField.getText(), null, "free_search", "SEARCH_PROFILE");
        }
        ImpGenericMessage igm = new ImpGenericMessage();
        igm.setSource(itm.getUser());
        igm.setSearchProfile(isp);

        contacts = itm.Contacts();

        itm.sendAll(contacts, igm);

        showLabelResults.setText("Searching...");
        while (itm.getBoolean() == false) {
            try {
                Thread.sleep(700);
            } catch (InterruptedException ex) {
                Logger.getLogger(Tabs.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (itm.getBoolean() == true) {
                showLabelResults.setText(null);
                break;
            }
        }
        results = itm.getFinalResults();
        if (results.get(0).getFileName().equalsIgnoreCase("There are no photos with this tags")) {
            showLabelResults.setText("There are no photos with these tags");
            try {
                File file = new File("icons", "warning_48.png");
                BufferedImage bufferedImage;
                bufferedImage = ImageIO.read(file);
                showLabelResults.setIcon(new ImageIcon(bufferedImage));
            } catch (IOException ex) {
                Logger.getLogger(Tabs.class.getName()).log(Level.SEVERE, null, ex);
            }
            node = new DefaultMutableTreeNode("Photos");
            treeModel = new DefaultTreeModel(node);
            jTree1 = new javax.swing.JTree(treeModel);
            jTree1.addMouseListener(new java.awt.event.MouseAdapter() {

                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    SelectPhotoSearch(evt);
                }
            });
            jScrollPane5.setViewportView(jTree1);
            results = null;
        } else {
            node = new DefaultMutableTreeNode("Photos");
            treeModel = new DefaultTreeModel(node);
            ImpPhoto temp = null;
            for (int i = 0; i < results.size(); i++) {
                temp = results.get(i);
                seleccion = new DefaultMutableTreeNode(temp.getFileName());
                treeModel.insertNodeInto(seleccion, node, 0);

            }
            jTree1 = new javax.swing.JTree(treeModel);
            jTree1.addMouseListener(new java.awt.event.MouseAdapter() {

                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    SelectPhotoSearch(evt);
                }
            });
            jScrollPane5.setViewportView(jTree1);
        }

    }//GEN-LAST:event_SearcherSearchButtonActionPerformed

    private void EditPhotoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditPhotoButtonActionPerformed
        Editor.setVisible(true);
        Editor.setVerifyInputWhenFocusTarget(rootPaneCheckingEnabled);
    }//GEN-LAST:event_EditPhotoButtonActionPerformed

    private void SelectFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectFileButtonActionPerformed
        // TODO add your handling code here:
        Upload_popup a = new Upload_popup();
        showPreview.setEnabled(true);
        showPreview.setOpaque(false);
        if (a.getFile() != null) {
            fileObtained = a.getFile();

            imagePlanar = JAI.create("fileload", fileObtained.getAbsolutePath());
            displayUpload = new DisplayJAI(imagePlanar);
            int width = imagePlanar.getWidth();
            int heigh = imagePlanar.getHeight();
            BufferedImage image = resize(imagePlanar, 616, 383);
            scaledImageRotate = PlanarImage.wrapRenderedImage(image);


            showPreview.setIcon(new ImageIcon(image));

        }



    }//GEN-LAST:event_SelectFileButtonActionPerformed

    private void EditorShareButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditorShareButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_EditorShareButtonActionPerformed

    private void EdgeDetectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EdgeDetectionButtonActionPerformed

        float[] kernelMatrix = {-1, -2, -1,
            30, 0, 0,
            1, 2, 1};
        KernelJAI kernel = new KernelJAI(3, 3, kernelMatrix);
        PlanarImage output = JAI.create("convolve", scaledImageprin, kernel);
        float data_h[] = new float[]{1.0F, 0.0F, -1.0F,
            1.414F, 0.0F, -1.414F,
            1.0F, 0.0F, -1.0F};
        float data_v[] = new float[]{-1.0F, -1.414F, -1.0F,
            0.0F, 0.0F, 0.0F,
            1.0F, 1.414F, 1.0F};
        KernelJAI kern_h = new KernelJAI(3, 3, data_h);
        KernelJAI kern_v = new KernelJAI(3, 3, data_v);
        PlanarImage im1 =
                (PlanarImage) JAI.create("gradientmagnitude", scaledImageprin,
                kern_h, kern_v);
        display.set(im1);

    }//GEN-LAST:event_EdgeDetectionButtonActionPerformed

    private void SelectImageEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SelectImageEditorButtonActionPerformed
        Upload_popup a = new Upload_popup();
        panelEditScroll.setEnabled(true);
        panelEditScroll.setOpaque(false);
        panelEditScroll.setVisible(true);
        constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 0;
        constraints.weighty = 0;

        constraints.anchor = GridBagConstraints.FIRST_LINE_END;
        if (a.getFile() != null) {
            phototoEdit = a.getFile();
            imagePlanar = JAI.create("fileload", phototoEdit.getAbsolutePath());
            int width = imagePlanar.getWidth();
            int heigh = imagePlanar.getHeight();
            float scale = 1f;
            if (heigh > 361) {
                scale = 361f / heigh;
            }
            if (width > 861 && heigh < 361) {
                scale = 861f / width;
            }
            numero = 100;
            display = new DisplayJAI(imagePlanar);
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(imagePlanar);
            pb.add(scale);
            pb.add(scale);
            pb.add(0.0F);
            pb.add(0.0F);
            pb.add(new InterpolationNearest());
            scaledImageprin = JAI.create("scale", pb, null);
            display.set(scaledImageprin);

            scaledImageRotate = scaledImageprin;

            int x = scaledImageRotate.getHeight();
            int y = scaledImageRotate.getWidth();

            picCont.setSize(y, x);

            picCont.add(display);

            editScroll.setBounds(100, 40, y, x);
            editScroll.setEnabled(false);
            editScroll.setViewportView(picCont.getComponent(0));

            LuminanceSlider.setValue(1);
            SharpeningSlider.setValue(20);
        }
   }//GEN-LAST:event_SelectImageEditorButtonActionPerformed

    private void localSearchButton(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localSearchButton
        String lSearch;
        results = new ArrayList();
        lSearch = LocalSearchField.getText();
        path = true;

        ImpPhoto pruebaphoto = new ImpPhoto();
        Object[] Parameters = new String[]{lSearch};
        DbDAO ins = DatabaseDao.getInstance();
        ins.seachBySpecificTag(Parameters);
        Map<String, ImpPhoto> result;
        result = ins.seachBySpecificTag(Parameters);
        if (result.isEmpty()) {
            jLabel1.setText("There are no photos with these tags");

            File file = new File("icons", "warning_48.png");
            PlanarImage im = JAI.create("fileload", file.getPath());
            BufferedImage bufferedImage = resize(im, 300, 300);
            jLabel1.setIcon(new ImageIcon(bufferedImage));

            node = new DefaultMutableTreeNode("Photos");
            treeModel = new DefaultTreeModel(node);
            jTree1 = new javax.swing.JTree(treeModel);
            jScrollPane5.setViewportView(jTree1);
        } else {
            java.util.List<String> phs = new ArrayList<String>(result.keySet());
            Collections.sort(phs);

            for (Iterator iterator = phs.iterator(); iterator.hasNext();) {
                String id = (String) iterator.next();
                pruebaphoto = result.get(id);
                results.add(pruebaphoto);
            }

        }
        node = new DefaultMutableTreeNode("Photos");
        DefaultMutableTreeNode temp;
        treeModel = new DefaultTreeModel(node);
        for (int i = 0; i < results.size(); i++) {
            tempo = results.get(i);
            temp = new DefaultMutableTreeNode(tempo.getFileName());
            treeModel.insertNodeInto(temp, node, 0);
        }
        LibraryTree = new javax.swing.JTree(treeModel);
        LibraryTree.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                libraryTreeClick(evt);
            }
        });
        jScrollPane2.setViewportView(LibraryTree);
    }//GEN-LAST:event_localSearchButton

    private void CheckBoxCategoriesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CheckBoxCategoriesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CheckBoxCategoriesActionPerformed

    private void CheckBoxNewsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CheckBoxNewsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CheckBoxNewsActionPerformed

    private void editZoomOut(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editZoomOut
        // TODO add your handling code here:
        if (numero > 50) {
            numero = numero - 20;
            float scale = numero / 100;
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(scaledImageRotate);
            pb.add(scale);
            pb.add(scale);
            pb.add(0.0F);
            pb.add(0.0F);
            pb.add(new InterpolationNearest());
            scaledImage = JAI.create("scale", pb, null);
            display.set(scaledImage);
        }
    }//GEN-LAST:event_editZoomOut

    private void editRotateRight(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRotateRight
        numero = 100;
        float angle = (float) Math.toRadians(90);
        float centerX = scaledImageprin.getWidth() / 2f;
        float centerY = scaledImageprin.getHeight() / 2f;
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(scaledImageRotate);
        pb.add(centerX);
        pb.add(centerY);
        pb.add(angle);
        pb.add(new InterpolationBilinear());
        scaledImageRotate = JAI.create("rotate", pb);
        display.set(scaledImageRotate);
    }//GEN-LAST:event_editRotateRight

    private void UpdateRotateRight(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UpdateRotateRight
        float angle = (float) Math.toRadians(90);
        float centerX = scaledImageRotate.getWidth() / 2f;
        float centerY = scaledImageRotate.getHeight() / 2f;
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(scaledImageRotate);
        pb.add(centerX);
        pb.add(centerY);
        pb.add(angle);
        pb.add(new InterpolationBilinear());
        scaledImageRotate = JAI.create("rotate", pb);
        BufferedImage image = resize(scaledImageRotate, 616, 383);
        showPreview.setIcon(new ImageIcon(image));
    }//GEN-LAST:event_UpdateRotateRight

    private void UploadRotateLeft(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UploadRotateLeft
        float angle = (float) Math.toRadians(-90);
        float centerX = scaledImageRotate.getWidth() / 2f;
        float centerY = scaledImageRotate.getHeight() / 2f;
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(scaledImageRotate);
        pb.add(centerX);
        pb.add(centerY);
        pb.add(angle);
        pb.add(new InterpolationBilinear());
        scaledImageRotate = JAI.create("rotate", pb);
        BufferedImage image = resize(scaledImageRotate, 616, 383);
        showPreview.setIcon(new ImageIcon(image));
    }//GEN-LAST:event_UploadRotateLeft

    private void editRotateLeft(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRotateLeft
        numero = 100;
        float angle = (float) Math.toRadians(-90);
        float centerX = scaledImageprin.getWidth() / 2f;
        float centerY = scaledImageprin.getHeight() / 2f;
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(scaledImageRotate);
        pb.add(centerX);
        pb.add(centerY);
        pb.add(angle);
        pb.add(new InterpolationBilinear());
        scaledImageRotate = JAI.create("rotate", pb);
        display.set(scaledImageRotate);
    }//GEN-LAST:event_editRotateLeft

    private void editZoomIn(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editZoomIn
        // TODO add your handling code here:
        if (numero < 200) {
            numero = numero + 20;
            float scale = numero / 100;
            ParameterBlock pb = new ParameterBlock();
            pb.addSource(scaledImageRotate);
            pb.add(scale);
            pb.add(scale);
            pb.add(0.0F);
            pb.add(0.0F);
            pb.add(new InterpolationNearest());
            scaledImage = JAI.create("scale", pb, null);
            display.set(scaledImage);
        }
    }//GEN-LAST:event_editZoomIn

    private void Logout(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Logout
        // TODO add your handling code here:
        itm.logout();
        this.setVisible(false);
        inicio.setVisible(true);
    }//GEN-LAST:event_Logout

    private void click(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_click
        // TODO add your handling code here:
        if (cont == 0) {
            TagsField.setText("");
            cont = 1;
        }
        if (cont == 2) {
            TagsField.setText("");
            cont = 3;
        }

    }//GEN-LAST:event_click

    private void upload(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upload
        // TODO add your handling code here:

        ImpPhoto photoToUpload = new ImpPhoto();
        int index1 = itm.getUsername().indexOf("@");
        String username = itm.getUsername().substring(0, index1);
        photoToUpload.setUserId(username);

        Calendar c = new GregorianCalendar();

        int hour, minutes, year, day, month;
        day = c.get(Calendar.DATE);

        month = c.get(Calendar.MONTH);
        month = month + 1;
        year = c.get(Calendar.YEAR);
        hour = c.get(Calendar.HOUR_OF_DAY);
        minutes = c.get(Calendar.MINUTE);
        photoToUpload.setUpdateDate(day, month, year);
        photoToUpload.setHour(hour, minutes);
        comment = CommentsField.getText();
        photoToUpload.setTags(tagsList);
        photoToUpload.setComment(comment);
        if (fileObtained == null) {
            JOptionPane.showMessageDialog(null, "You don't select any photo",
                    "You don't select any photo", JOptionPane.ERROR_MESSAGE);
        } else {
            File fileOut = new File("outcoming", fileObtained.getName());
            String realName = fileObtained.getName();
            int index = realName.indexOf(".");
            realName = realName.substring(0, index);
            photoToUpload.setName(realName);
            photoToUpload.setSize(fileObtained.length());
            realName = fileObtained.getName().substring(index + 1, fileObtained.getName().length());
            photoToUpload.setExtension(realName);



            try {
                InputStream in = new FileInputStream(fileObtained);
                OutputStream out = new FileOutputStream(fileOut);
                byte[] buf = new byte[1024];
                int len;
                try {
                    while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }
                    in.close();
                    out.close();
                } catch (IOException ex) {
                    Logger.getLogger(Upload_popup.class.getName()).log(Level.SEVERE, null, ex);
                }
                icon = new ImageIcon(fileOut.getAbsolutePath());
                photoToUpload.setDimension(icon.getIconWidth(), icon.getIconHeight());
                photoToUpload.setUrl(fileOut.getAbsolutePath());

            } catch (IOException ex) {
                Logger.getLogger(Tabs.class.getName()).log(Level.SEVERE, null, ex);
            }


        }
        if (CheckBoxCategoUpload.isSelected() && !taxType_name.equalsIgnoreCase("Categories")) {
            taxs.put(taxType, taxType_name);
            photoToUpload.setTaxs(taxs);


        }
        if (CheckBoxCategoUpload.isSelected() && taxType_name.equalsIgnoreCase("Categories")) {
            JOptionPane.showMessageDialog(null, "Categories is not a valid tax name",
                    "Error", JOptionPane.ERROR_MESSAGE);
        } else {

            DbDAO ins = DatabaseDao.getInstance();
            ins.insertPhoto(photoToUpload);

            comment = null;
            CommentsField.setText(null);
            tagsList = new ArrayList();
            node = new DefaultMutableTreeNode("Outcoming");
            DefaultMutableTreeNode temp;
            File file = new File("outcoming");
            treeModel = new DefaultTreeModel(node);
            File[] filesTree = file.listFiles(new ImageFileFilter());
            for (File f : filesTree) {
                temp = new DefaultMutableTreeNode(f.getName());
                treeModel.insertNodeInto(temp, node, 0);

            }
            LibraryTree = new javax.swing.JTree(treeModel);
            LibraryTree.addMouseListener(new java.awt.event.MouseAdapter() {

                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    libraryTreeClick(evt);
                }
            });
            jScrollPane2.setViewportView(LibraryTree);
        }

    }//GEN-LAST:event_upload

    private void deleteComments(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_deleteComments
        // TODO add your handling code here:

        if (cont == 0) {
            CommentsField.setText("");
            cont = 2;
        }
        if (cont == 1) {
            CommentsField.setText("");
            cont = 3;
        }

    }//GEN-LAST:event_deleteComments

    private void addTag(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTag
        // TODO add your handling code here:
        //tagsList=new ArrayList();
        boolean repeat = false;
        for (int i = 0; i < tagsList.size(); i++) {
            if (tagsList.get(i).toString().equalsIgnoreCase(TagsField.getText())) {
                JOptionPane.showMessageDialog(null, "The tag is already added",
                        "The tag is already added", JOptionPane.ERROR_MESSAGE);
                repeat = true;
                break;
            }
        }
        if (repeat == false) {
            tagsList.add(TagsField.getText());
            TagsField.setText("");
        }
    }//GEN-LAST:event_addTag

    private void clear(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clear

        node = new DefaultMutableTreeNode("Photos");
        treeModel = new DefaultTreeModel(node);
        jTree1 = new javax.swing.JTree(treeModel);
        jScrollPane5.setViewportView(jTree1);
        results = null;
        totalResults = null;
        showLabelResults.setIcon(null);
        showLabelResults.setText(null);
        SearchField.setText(null);



    }//GEN-LAST:event_clear
    public String findTaxofTree(TreePath tree) {
        Object[] taxss;
        taxss = tree.getPath();
        if (taxss.length > 2) {
            return taxss[taxss.length - 2].toString();

        } else if (taxss.length == 2) {
            return taxss[0].toString();
        } else {
            return taxss[taxss.length - 1].toString();
        }
    }
    private void libraryTreeClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_libraryTreeClick
        // TODO add your handling code here:
        jLabel1.setText(null);
        libraryClick = LibraryTree.getLastSelectedPathComponent().toString();
        File photo;
        PlanarImage ima;
        BufferedImage image;
        if (path == true) {
            for (int a = 0; a < results.size(); a++) {
                if ((results.get(a).getFileName()).equalsIgnoreCase(libraryClick)) {
                    photo = new File("outcoming", results.get(a).getFileName() + "." + results.get(a).getFileExtension());
                    ima = JAI.create("fileload", photo.getPath());
                    image = resize(ima, jLabel1.getHeight(), jLabel1.getWidth());
                    jLabel1.setIcon(new ImageIcon(image));

                    String temp = "<html>From: "
                            + results.get(a).getUserId()
                            + "<br />Comment: " + results.get(a).getComment()
                            + "<br />Upload date: " + results.get(a).getUpdateDate() + "  " + " Hour: " + results.get(a).getHour()
                            + "<br />Name: " + results.get(a).getFileName()
                            + "<br />"
                            + "<br />Extension: " + results.get(a).getFileExtension()
                            + "<br />Dimensions: " + results.get(a).getDimensions()
                            + "<br />Size: " + results.get(a).getSize() + "</html>";
                    jLabel1.setText(temp);
                    break;
                }

            }
        } else {
            photo = new File("outcoming", libraryClick);
            ima = JAI.create("fileload", photo.getPath());
            image = resize(ima, jLabel1.getHeight(), jLabel1.getWidth());
            jLabel1.setIcon(new ImageIcon(image));
        }
    }//GEN-LAST:event_libraryTreeClick

    private void UploadOntologyListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UploadOntologyListener
        // TODO add your handling code here:

        if (OntologiesUpload.getLastSelectedPathComponent() != null) {
            taxType = findTaxofTree(OntologiesUpload.getAnchorSelectionPath()).toLowerCase(Locale.FRENCH);
            taxType_name = OntologiesUpload.getLastSelectedPathComponent().toString().toLowerCase(Locale.FRENCH);
        }
    }//GEN-LAST:event_UploadOntologyListener

    private void SelectPhotoSearch(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SelectPhotoSearch
        // TODO add your handling code here:
        tempo = new ImpPhoto();
        Object prove = jTree1.getLastSelectedPathComponent();
        if (prove != null) {
            selected = jTree1.getLastSelectedPathComponent().toString();
            for (int a = 0; a < results.size(); a++) {
                if (results.get(a).getFileName().equalsIgnoreCase(selected)) {
                    userCatch = results.get(a).getUserId();
                    userCatch = userCatch + "@gmail.com";
                    break;
                }
            }
            for (int a = 0; a < results.size(); a++) {
                if (selected.equalsIgnoreCase(results.get(a).getFileName())) {
                    tempo = results.get(a);
                    downloadPhoto.setVisible(true);
                    showLabelResults.setIcon(results.get(a).getThumbnail().getIcon());
                    String temp = "<html>From: "
                            + results.get(a).getUserId()
                            + "<br />Comment: " + results.get(a).getComment()
                            + "<br />Upload date: " + results.get(a).getUpdateDate() + "  " + " Hour: " + results.get(a).getHour()
                            + "<br />Name: " + results.get(a).getFileName()
                            + "<br />"
                            + "<br />Extension: " + results.get(a).getFileExtension()
                            + "<br />Dimensions: " + results.get(a).getDimensions()
                            + "<br />Size: " + results.get(a).getSize() + "</html>";
                    showLabelResults.setText(temp);

                }
            }
        }
    }//GEN-LAST:event_SelectPhotoSearch

    private void downloadPhotoAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadPhotoAction
        // TODO add your handling code here:

        if (selected == null) {
            JOptionPane.showConfirmDialog(null, "You don't select any photo to download0", "Error", JOptionPane.ERROR_MESSAGE);
        }
        if (selected.equalsIgnoreCase("There are no photos with this tags")) {
            JOptionPane.showConfirmDialog(null, "You don't select any photo to download1", "Error", JOptionPane.ERROR_MESSAGE);
        }
        Object[] options = {"Yes", "No"};

        int n = JOptionPane.showOptionDialog(null,
                "Download this image " + selected + "?",
                "Confirmation",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null, //don't use a custom Icon
                options, //the titles of buttons
                options[0]);
        if (n == JOptionPane.YES_OPTION) {
            ImpUserContent iuc = new ImpUserContent(selected, "USER_CONTENT");
            ImpGenericMessage igm = new ImpGenericMessage();
            igm.setDestination(userCatch);
            igm.setSource(itm.getUser());
            igm.setUserContent(iuc);
            itm.sendMessage(igm.getDestination(), igm);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Tabs.class.getName()).log(Level.SEVERE, null, ex);
            }
            JFrame frame;
            frame = new JFrame("Show Message Dialog");
            while (itm.receBool().getBoolean() == false) {
            }
        }

    }//GEN-LAST:event_downloadPhotoAction
    public class ImageFileFilter implements FileFilter {

        private final String[] okFileExtensions =
                new String[]{"jpg", "jpeg", "png", "gif", "tiff"};

        public boolean accept(File file) {
            for (String extension : okFileExtensions) {
                if (file.getName().toLowerCase().endsWith(extension)) {
                    return true;
                }
            }
            return false;
        }
    }
    private void CheckBoxCategoUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CheckBoxCategoUploadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_CheckBoxCategoUploadActionPerformed

    private void ClearLocal(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearLocal
        // TODO add your handling code here:
        path = false;
        File filefil = new File("icons", "image_48.png");
        PlanarImage im = JAI.create("fileload", filefil.getPath());
        BufferedImage image = resize(im, 300, 300);
        jLabel1.setIcon(new ImageIcon(image));
        jLabel1.setText("Select any photo");
        LocalSearchField.setText(null);
        node = new DefaultMutableTreeNode("Outcoming");
        DefaultMutableTreeNode temp;
        File file = new File("outcoming");
        treeModel = new DefaultTreeModel(node);
        File[] filesTree = file.listFiles(new ImageFileFilter());
        for (File f : filesTree) {
            temp = new DefaultMutableTreeNode(f.getName());
            treeModel.insertNodeInto(temp, node, 0);

        }
        LibraryTree = new javax.swing.JTree(treeModel);
        LibraryTree.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {
                libraryTreeClick(evt);
            }
        });

        jScrollPane2.setViewportView(LibraryTree);


    }//GEN-LAST:event_ClearLocal

    private void LuminanceSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_LuminanceSliderStateChanged


        int kernelSize = LuminanceSlider.getValue();
        if (kernelSize > 0) {

            float[] kernelMatrix = new float[kernelSize * kernelSize];


            for (int k = 0; k < kernelMatrix.length; k++) {
                kernelMatrix[k] = 1.0f / (kernelSize * kernelSize);
            }

            PlanarImage input = scaledImageprin;

            KernelJAI kernel = new KernelJAI(kernelSize, kernelSize, kernelMatrix);
            // Run the convolve operator, creating the output image.
            scaledImageRotate = JAI.create("convolve", input, kernel);
            display.set(scaledImageRotate);
        }

    }//GEN-LAST:event_LuminanceSliderStateChanged

    private void SharpeningSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_SharpeningSliderStateChanged

        // TODO add your handling code here:
        SharpeningSlider.setValueIsAdjusting(true);
        BufferedImage image = resize(imagePlanar, 861, 361);
        SharpeningSlider.setMinimum(0);
        SharpeningSlider.setMaximum(200);
        int p = SharpeningSlider.getValue();

        float num = p / 20f;
        float[] factordeescala = {num, num, num};
        float[] desplazamiento = {0.0f, 0.0f, 0.0f};
        RescaleOp aumento = new RescaleOp(factordeescala, desplazamiento, null);
        BufferedImage images = aumento.filter((image), null);
        scaledImageRotate = PlanarImage.wrapRenderedImage(images);
        display.set(scaledImageRotate);

    }//GEN-LAST:event_SharpeningSliderStateChanged

    private void searchOntologyTree(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchOntologyTree
        // TODO add your handling code here:
    }//GEN-LAST:event_searchOntologyTree
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AddCommentText;
    private javax.swing.JLabel AddTagsField;
    private javax.swing.JTextField AllCategoriesSelectedField;
    private javax.swing.JCheckBox CheckBoxCategoUpload;
    private javax.swing.JCheckBox CheckBoxCategories;
    private javax.swing.JCheckBox CheckBoxNews;
    private javax.swing.JTextField CommentsField;
    private javax.swing.JComboBox DifferentNewsSearchMenu;
    private javax.swing.JButton EdgeDetectionButton;
    private javax.swing.JButton EditPhotoButton;
    private javax.swing.JPanel Editor;
    private javax.swing.JButton EditorDiscardButton;
    private javax.swing.JButton EditorSaveButton;
    private javax.swing.JButton EditorShareButton;
    private javax.swing.JPanel Library;
    private javax.swing.JButton LibraryDeletePhotoButton;
    private javax.swing.JButton LibraryPresentationButton;
    private javax.swing.JTree LibraryTree;
    private javax.swing.JTextField LocalSearchField;
    private javax.swing.JLabel LocalSearchTitle;
    private javax.swing.JButton LogoutButton;
    private javax.swing.JSlider LuminanceSlider;
    private javax.swing.JLabel LuminanceText;
    private javax.swing.JTree OntologiesSearcher;
    private javax.swing.JTree OntologiesUpload;
    private javax.swing.JLabel PreviewTitle;
    private javax.swing.JLabel ResultsText;
    private javax.swing.JPanel Search;
    private javax.swing.JButton SearchButton;
    private javax.swing.JTextField SearchField;
    private javax.swing.JLabel SearchText;
    private javax.swing.JButton SearcherClearButton;
    private javax.swing.JButton SearcherSearchButton;
    private javax.swing.JButton SelectFileButton;
    private javax.swing.JTextField SelectFileField;
    private javax.swing.JLabel SelectFileText;
    private javax.swing.JButton SelectImageEditorButton;
    private javax.swing.JSlider SharpeningSlider;
    private javax.swing.JLabel SharpeningText;
    private javax.swing.JTextField TagsField;
    private javax.swing.JLabel TreeMenuText;
    private javax.swing.JPanel Upload;
    private javax.swing.JButton UploadButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton downloadPhoto;
    private javax.swing.JScrollPane editScroll;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLayeredPane jLayeredPane3;
    private javax.swing.JLayeredPane jLayeredPane4;
    private javax.swing.JLayeredPane jLayeredPane7;
    private javax.swing.JLayeredPane jLayeredPane9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTabbedPane jTabbedPane5;
    private javax.swing.JTree jTree1;
    private javax.swing.JTabbedPane menu;
    private javax.swing.JPanel panelDePhoto;
    private javax.swing.JPanel panelEditScroll;
    private javax.swing.JLabel picCont;
    private javax.swing.JLabel showLabelResults;
    private javax.swing.JLabel showPreview;
    private javax.swing.JButton zoomin;
    private javax.swing.JButton zoomout;
    // End of variables declaration//GEN-END:variables
}
